package com.ydd.mapper;

import com.ydd.dto.ArticleListDTO;
import com.ydd.entity.Article;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ydd.vo.AritllllllVO;
import com.ydd.vo.HotArticleVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hgz
 * @since 2023-05-30
 */
@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

    /**
     * 获取文章总数
     * @return
     */
    @Select("select count(*) from ydd_article")
    Integer getCount();

    @Select("select * from ydd_article order by click desc limit 7")
    List<Article> getHotArticle();


    /**
     * 获取当前登录用户所有我的文章
     * @param userId
     * @return
     */
    @Select("select * from youdianda.ydd_article where user_id = #{userId}")
    List<Article> getArticleList(Integer userId);

    /**
     * 获取当前登录用户所有我的收藏或者点赞文章
     * @param getArticleIds
     * @return
     */
    List<Article> getCollectionArticleList(@Param("getArticleIds") List<Integer> getArticleIds);

    /**
     * 添加收藏
     * @param articleid
     */
    @Update("update ydd_article set lovenum = lovenum + 1 where id = #{articleid}")
    void loveNumPlus(Integer articleid);

    /**
     * 取消收藏
     * @param articleid
     */
    @Update("update ydd_article set lovenum = lovenum - 1 where id = #{articleid}")
    void loveNumMin(Integer articleid);

    /**
     * 点赞
     * @param articleid
     */
    @Update("update ydd_article set click = click + 1 where id = #{articleid}")
    void clickPlus(Integer articleid);

    /**
     * 取消点赞
     * @param articleid
     */
    @Update("update ydd_article set click = click - 1 where id = #{articleid}")
    void clickMin(Integer articleid);


    @Select("select count(*) from ydd_article where create_date >= #{begin}")
    Integer findByBeginTime(Long begin);

    //@Select("select * from ydd_article where cateid = #{cateid} order by click desc ")
    List<Article> page(Integer catrid);

    List<HotArticleVO> list();

    @Select("select id,lovenum,pic,title from ydd_article where ishot = 1 limit 6")
    List<HotArticleVO> hotList();


    List<AritllllllVO> select(ArticleListDTO articleListDTO);
}
